package com.example.shop.user.dto;

import com.example.shop.common.api.ResponseResult;
import com.example.shop.common.dto.Avatar;
import com.example.shop.pojo.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.InnerField;
import org.springframework.data.elasticsearch.annotations.MultiField;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class UserBriefInfo extends Avatar {
    /**
     * 名称
     */
    @MultiField(
            mainField = @Field(type = FieldType.Text, analyzer = "ik_max_word",searchAnalyzer = "ik_max_word"),
            otherFields = {
                    @InnerField(suffix = "keyword",type = FieldType.Keyword)
            }
    )
    protected String name;

    /**
     * 根据user获取响应给前端的用户简单信息
     * @param user 用户信息
     * @return 返回响应给前端的用户简单信息
     */
    public static UserBriefInfo getUserBriefInfo(User user){
        UserBriefInfo userBriefInfo = new UserBriefInfo();
        userBriefInfo.setId(user.getUserId());
        userBriefInfo.setName(user.getUserName());
        userBriefInfo.setAvatar(user.getUserAvatar());
        return userBriefInfo;
    }

    @Override
    public String toString() {
        return "UserBriefInfo{" +
                super.toString()+
                "name ='" + name + '\'' +
                '}';
    }
}
